package demo1;

import java.util.Objects;
abstract interface A
{

}

class Person{
    private String name;
    private int age;
    public Person(String name,int age){
        this.name = name;
        this.age = age;
    }
    //重写equals（）方法
    @Override
    public boolean equals(Object obj){
        if(obj == null){
            return false;
        }else if(this == obj){
            return true;
        }
        //判断是不是Person对象，是不是同种类型
        if(!(obj instanceof Person)){
            return false;
        }
        Person per = (Person) obj;
        if(this.name.equals(per.name) && this.age == per.age){
            return true;
        }
        return false;
    }
//重写hashCode（）方法
    @Override
    public int hashCode(){
        return Objects.hash(this.name,this.age);
    }


//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Person person = (Person) o;
//        return age == person.age && Objects.equals(name, person.name);
//    }
//
//    @Override
//    public int hashCode() {
//        return Objects.hash(name, age);
//    }
}
class Student{

}

public class Test {
    public static void func(Object obj){
        System.out.println(obj);
    }

    public static void main(String[] args) {
        /*func(new Person());
        func(new Student());*/
        Person person = new Person("张三",18);
        Person person1 = new Person("张三",18);
        System.out.println(person.equals(person1));
        System.out.println("=========================");
        System.out.println(person.hashCode());
        System.out.println(person1.hashCode());//方法重载 参数类型为int
        System.out.println(person);//方法重载 参数类型为OBject

    }

}
